package com.mms.utsc.smartnet;

import java.util.ArrayList;

import android.app.Activity;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.AsyncTask;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

public class ListViewImageTextAdapter extends BaseAdapter {

	private LayoutInflater inflater = null;
	ImageView image;
	private int itemLayoutID = -1;
	private Activity parentActivity;
	ArrayList<MenuListItem> menuListItems;

	public ListViewImageTextAdapter(Activity parentActivity, ArrayList<MenuListItem> menuListItems, int itemLayoutId) {
		this.inflater = (LayoutInflater) parentActivity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
		this.itemLayoutID = itemLayoutId;
		this.parentActivity = parentActivity;
		this.menuListItems = menuListItems;
	}

	public View getView(int position, View convertView, ViewGroup parent) {
		View view = convertView;
		if (convertView == null)
			view = inflater.inflate(this.itemLayoutID, null);
		// This adapter is made for main menu

		TextView text = (TextView) view.findViewById(R.id.tvListViewText);
		image = (ImageView) view.findViewById(R.id.ivListViewImage);

		text.setText(menuListItems.get(position).getMenuItemText());
		Bitmap imageToDisplay = BitmapFactory.decodeResource(view.getResources(), menuListItems.get(position).getMenuItemImageID());
		image.setImageBitmap(imageToDisplay);

		return view;
	}

	public int getCount() {
		// TODO Auto-generated method stub
		return menuListItems.size();
	}

	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return menuListItems.get(position);
	}

	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}
}
